﻿$(document).ready(function () {
    $(".friendsInvite").click(function (e) {
        e.preventDefault();
        FB.ui({
            method: 'apprequests',
            message: user.name + ' ชวนคุณมาร่วมสนุกกับเกมทายผลกีฬา ชิงเงินรางวัล iFunSport http://www.ifunsport.com'
        }, function (data) {
            if (data != null) {

                var requests = [];
                jQuery.each(data.to, function (i,d) {
                    requests.push({
                        requestId: data.request,
                        requesterId: user.id,
                        requestTo: d,
                        requesterEmail :user.email
                    });
                });
                var data2 = JSON.stringify(requests);
                $.ajax({
                    url: 'http://ifunsport.com/ifs.ashx?metdhodName=addinviteFriend',
                    type: 'POST',
                    dataType: "json",
                    data: { postData: data2 },
                    success: function (data) {

                        if (data.result == false) {
                            //alert(data.msg);
                            return false;
                        }
                        else {
                            //alert(data.msg);

                            return false;
                        }
                    }
                });
            }
        });
    });
});
